package com.example.testapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

public class ArticleManagementActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article_management);





        RecyclerView recyclerView = findViewById(R.id.recyclerViewArticle);
        List<Question> list = new ArrayList<>();
        for (int i = 0;i < 10; i++) {
            Question question = new Question();
            question.setTitle("淄博市周村区涿河、米河流域绿化改造工程施工米河流域"+i);
            list.add(question);
        }
        final ArticleRecyclerViewAdapter adapter = new ArticleRecyclerViewAdapter(list);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

        ImageView ivBack = findViewById(R.id.ivBack2);

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        recyclerView.post(new Runnable() {
            @Override
            public void run() {
                adapter.setOnClick(new ArticleRecyclerViewAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, final int position) {
                        DialogActivity dialog = new DialogActivity(ArticleManagementActivity.this);
                        dialog.setCancel(new DialogActivity.IOnCancelListener() {
                            @Override
                            public void onCancel(DialogActivity dialog) {
                            }
                        });
                        dialog.setConfirm(new DialogActivity.IOnConfirmListener() {
                            @Override
                            public void onConfirm(DialogActivity dialog) {
                                adapter.removeData(position);

                            }
                        });
                        dialog.show();

//                        View dialogView = LayoutInflater.from(ArticleManagementActivity.this).inflate(R.layout.activity_dialog,null);
//                        Button btnCancel = dialogView.findViewById(R.id.btnCancel);
//                        Button btnConfirm = dialogView.findViewById(R.id.btnConfirm);
//                        final AlertDialog.Builder layoutDialog = new AlertDialog.Builder(ArticleManagementActivity.this);
//                        layoutDialog.setView(dialogView);
//                        btnConfirm.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                adapter.removeData(position);
//                                layoutDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
//                                    @Override
//                                    public void onCancel(DialogInterface dialog) {
//                                        dialog.cancel();
//                                    }
//                                });
//                            }
//                        });
//                        btnCancel.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                Log.e("Tag","1");
//                                layoutDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
//                                    @Override
//                                    public void onDismiss(DialogInterface dialog) {
//                                        Log.e("Tag","11");
//                                        dialog.dismiss();
//                                    }
//                                });
//                            }
//                        });
//                        layoutDialog.create().show();

//                        AlertDialog.Builder builder = new AlertDialog.Builder(ArticleManagementActivity.this);
////                        builder.setTitle("删除后，不可恢复，确定删除吗？");
//                        builder.setNeutralButton("取消", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                            }
//                        });
//                        builder.setNegativeButton("确认", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                adapter.removeData(position);
//                            }
//                        });
//                        builder.show();
                    }
                });
            }
        });

    }

}
